home *** CD-ROM | disk | FTP | other *** search
- /*///////////////////////////////////////////*/
- /* T E S T K E Y . C */
- /* Compilation instructions: */
- /* */
- /* MICROSOFT 5.0 */
- /* cl -c -ms testkey.c */
- /* link testkey inputs.lib; */
- /*///////////////////////////////////////////*/
- #include <stdio.h>
- #include <conio.h>
- #include <dos.h>
- #include "input.h"
-
- /*////////////////////////////////////////////////*/
- /* USER DEFINED EXCEPTION KEY HANDLER PROTOTYPES */
- /*////////////////////////////////////////////////*/
- void StringHandler(char);
- void AlphaHandler(char);
- void LogicalHandler(char);
- void LongHandler(char);
- void DoubleHandler(char);
- void DateHandler(char);
- void nestedfunction(char);
- void StartHandler(char);
-
- /*//////////////////////////////////////////*/
- /* FUNCTIONS THAT YOU CAN REPLACE FOR SPEED */
- /*//////////////////////////////////////////*/
- void gettext(int startx, int endx,
- int starty, int endy, unsigned char *buff);
- void puttext(int startx, int endx,
- int starty, int endy, unsigned char *buff);
- void ClrLine(int);
-
- /*///////////////////*/
- /* INPUT DATA FIELDS */
- /*///////////////////*/
- char string[21];
- char YesNo = YES;
- int width;
- long LongNum;
- double DoubleNum;
- int decimals;
- char datestring[] = " / / "; /* DATE STRING MUST BE IN THIS FORMAT */
- static char buffer[2000]; /* AN ARRAY TO HOLD VIDEO, SHOULD BE */
- void main(void) /* 4000 IN SIZE FOR A COMPLETE SCREEN */
- {
- clrscr();
- printf("During the input of the data fields, press any of the function\n");
- printf("keys to execute exception key handlers. The first function for\n");
- printf("alphanumeric input has an example of nested input. Its handler\n");
- printf("will call the logical input function which in turn has an\n");
- printf("exception handler of its own. The program was purposely kept\n");
- printf("as simple as possible so you could more easily see how the\n");
- printf("functions are used in the source code for this example program.\n");
- printf("Structures could be used for input or windows popped up,\n");
- printf("but I'll leave those function to written by you. There are\n");
- printf("plenty of library routines that do windows and colors in the\n");
- printf("public domain. Those routines combined with the routines in\n");
- printf("the INPUT.LIB file will greatly enhance your capabilities\n");
- printf("in the programming arena. While testing the following input\n");
- printf("functions, at anytime press the function keys and the value of\n");
- printf("the key will be displayed. This value can be used to determine\n");
- printf("the action that your handler will take.\n\n");
- printf("While answering the next prompt, press the function keys.\n\n");
- printf("Continue with demo? [ ]\b\b");
- YesNo = inputLogical(YesNo, StartHandler);
- if (YesNo == NO) {
- clrscr();
- return;
- }
-
- clrscr();
- gotoxy(2,0);
- printf("Enter alphanumeric data: ");
- inputString(string, sizeof string, StringHandler);
- printf("\n\nString entered was: %s\n\n", string);
- printf("Press any key to continue ...");
- waitkey();
-
- clrscr();
- gotoxy(2,0);
- printf("Enter alpha input only: ");
- inputAlpha(string, sizeof string, AlphaHandler);
- printf("\n\nString entered was %s\n\n", string);
- printf("Press any key to continue ...");
- waitkey();
-
- clrscr();
- gotoxy(2,0);
- printf("Enter Y/N only: [ ]\b\b");
- YesNo = inputLogical(YesNo, LogicalHandler);
- printf("\n\nLogical input was: %c\n\n", YesNo);
- printf("Press any key to continue ...");
- waitkey();
-
- clrscr();
- gotoxy(2,0);
- printf("Enter a long integer: ");
- LongNum = inputLong(11, LongHandler);
- printf("\n\nNumber entered was: %ld\n\n", LongNum);
- printf("Press any key to continue ...");
- waitkey();
-
- width = 20; /* THIS IS THE WIDTH OF THE DOUBLE NUMBER */
- decimals = 4; /* SET DECIMALS TO FOUR PLACES */
- clrscr();
- gotoxy(2,0);
- printf("Enter a double number: ");
- DoubleNum = inputDouble(width, decimals, DoubleHandler);
- printf("\n\nNumber entered was: %e\n\n", DoubleNum);
- printf("Same double number is: %f\n\n", DoubleNum);
- printf("Dollar amount is: $%.2f\n\n", DoubleNum);
- printf("Press any key to continue ...");
- waitkey();
-
- clrscr();
- gotoxy(2,0);
- printf("Enter a date MM/DD/YY: [ / / ]");
- gotoxy(2,24); /* PUT CURSOR IN CORRECT PLACE ON SCREEN FOR INPUT */
- inputDate(datestring, DateHandler);
- printf("\n\nDate entered was: %s\n\n", datestring);
-
- printf("End of test key program ...\n\n");
-
- return;
- }
-
- /*////////////////////////////////////////////////////////////////
- /* The following functions are stub functions. These functions */
- /* could be written to save a portion of the screen, display a */
- /* message, do a nested input function, or whatever you please */
- /* based on the value of the exception key. Exception keys are */
- /* defined as any key that is not normal input and is not a key */
- /* that exits the current field being input. If you want */
- /* nothing done, simply execute a return statement. These */
- /* functions are part of the interface to the input routines */
- /* and must exist. See INPUT.DOC for more information. */
- /*//////////////////////////////////////////////////////////////*/
-
- void StartHandler(char excpt_key) { /* This function demonstates */
- static char buffer[4000]; /* how your functions could */
- gettext(3,10,8,50, buffer); /* save a portion of the */
- gotoxy(5,15); /* screen ... */
- printf("Key value is %d", excpt_key);
- gotoxy(6,15);
- printf("Press any non function key ... ");
- waitkey();
-
- puttext(3,10,8,50, buffer); /* ... and then restore it */
- return; /* before your handler */
- } /* returns. */
-
- void StringHandler(char excpt_key) {
- char key;
- key = YES;
- gotoxy(0,0);
- printf(
- "Instring handler with key %d, F1-F10 for nested input. Exit? Y/N: [ ]\b\b",
- excpt_key);
- key = inputLogical(key, nestedfunction);
- gotoxy(20,1);
- if (key == YES)
- printf("TRUE condition, press any key to continue ...", key);
- else
- printf("FALSE condition, press any key to continue ...", key);
- waitkey();
- ClrLine(20);
- ClrLine(0);
- return;
- }
-
- void AlphaHandler(char excpt_key) {
- gotoxy(0,0);
- printf("Alpha handler executed with key %d, any key ... ", excpt_key);
- waitkey();
- ClrLine(0);
- return;
- }
-
- void LogicalHandler(char excpt_key) {
- gotoxy(0,0);
- printf("Logical handler executed with key %d, any key ... ", excpt_key);
- waitkey();
- ClrLine(0);
- return;
- }
-
- void LongHandler(char excpt_key) {
- gotoxy(0,0);
- printf("Integer handler executed with key %d, any key ... ", excpt_key);
- waitkey();
- ClrLine(0);
- return;
- }
-
- void DoubleHandler(char excpt_key) {
- gotoxy(0,0);
- printf("Double handler executed with key %d, any key ...", excpt_key);
- waitkey();
- ClrLine(0);
- return;
- }
-
- void DateHandler(char excpt_key) {
- gotoxy(0,0);
- printf("Date handler executed with key %d, any key ...", excpt_key);
- waitkey();
- ClrLine(0);
- return;
- }
-
- void nestedfunction(char excpt_key) {
- gotoxy(14,0);
- printf("Nested function executed with key %d, any key ... ", excpt_key);
- waitkey();
- ClrLine(14);
- return;
- }
-
- /* ////////////////////////////////////////////////////////////////*/
- /* The following functions can be rewritten or renamed to increase */
- /* the speed. These were put here merely to show you how the */
- /* keyboard handlers can call other screen handlers to save part */
- /* of the screen and restore it or just erase one line. */
- /* ////////////////////////////////////////////////////////////////*/
- void ClrLine(row) {
- int i;
- gotoxy(row, 0);
- for (i = 0; i < 79; i++)
- putch(' ');
- return;
- }
-
- /*//////////////////////////////////////////////////////////*/
- /* This is a very slow function that saves a portion of the */
- /* screen. You can write your own preferably in assembly */
- /* language to speed this up. */
- /*//////////////////////////////////////////////////////////*/
- void gettext(int startx, int endx,
- int starty, int endy, unsigned char *buff) {
- union REGS r;
- register int i, j;
-
- for (i = starty; i < endy; i++)
- for (j = startx; j < endx; j++) {
- gotoxy(j, i);
- r.h.ah = 8;
- r.h.bh = 0;
- int86(0x10, &r, &r);
- *buff++ = r.h.al;
- *buff++ = r.h.ah;
- putchar('█');
- }
-
- for (i = starty+1; i < endy-1; i++)
- for (j = startx+1; j < endx-1; j++) {
- gotoxy(j, i);
- putchar(' ');
- }
- }
-
- /*//////////////////////////////////////////////////////////////*/
- /* This is also a very slow routine to restore a portion of the */
- /* screen. This is also a good candidate for assembly code. */
- /*//////////////////////////////////////////////////////////////*/
- void puttext(int startx, int endx,
- int starty, int endy, unsigned char *buff) {
- union REGS r;
- register int i, j;
-
- for (i = starty; i < endy; i++)
- for (j = startx; j < endx; j++) {
- gotoxy(j, i);
- r.h.ah = 9;
- r.h.bh = 0;
- r.x.cx = 1;
- r.h.al = *buff++;
- r.h.bl = *buff++;
- int86(0x10, &r, &r);
- }
- }
-